package com.vlong.town.service.suggestion;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.suggestion.Suggestion;
import com.vlong.town.mapper.suggestion.SuggestionMapper;


/**
 * 问题反馈业务实现类
 * @author Assassin
 */
@Service
public class SuggestionService {

	// Fields

	@Autowired
	private SuggestionMapper suggestionMapper;// 意见反馈Mapper接口

	// Methods

   /**
	* 添加问题反馈
	* @param suggestionId 反馈标识[主键值]
	* @param status 反馈状态[1-可用 | 2-不可用]
	* @param title 反馈标题
	* @param categoryId 问题类型
	* @param content 反馈内容
	* @param publishUserId 反馈人标识
	* @param publishUserName 反馈人姓名
	* @param telphone 电话号码
	* @param email 电子邮箱
	* @param publishUserType 反馈人类型[1-农户 | 2-专家 | 3-管理员]
	* @param isDeal 是否解决[1-是 | 2-否 默认2]
	* @param dealContent 解决方案
	* @param dealUserId 解决人标识
	* @param dealUserType 解决人类型[1-农户 | 2-专家  | 3-管理员]
	* @param createTime 反馈时间
	* @param updateTime 更新时间[初始化=创建时间]
	* @return Long suggestionId 添加后的数据库主键值
	*/
   @Transactional
	public Long add(Long suggestionId, Integer status, String title, Long categoryId, String content, Long publishUserId, String publishUserName, String telphone, String email, Integer publishUserType, Integer isDeal, String dealContent, Long dealUserId, Integer dealUserType, Long createTime, Long updateTime) {
		// 构造问题反馈参数实体
		Suggestion suggestion = new Suggestion();
		suggestion.setSuggestionId(suggestionId);// Set 反馈标识[主键值]
		suggestion.setStatus(status);// Set 反馈状态[1-可用 | 2-不可用]
		suggestion.setTitle(title);// Set 反馈标题
		suggestion.setCategoryId(categoryId);// Set 问题类型
		suggestion.setContent(content);// Set 反馈内容
		suggestion.setPublishUserId(publishUserId);// Set 反馈人标识
		suggestion.setPublishUserName(publishUserName);// Set 反馈人姓名
		suggestion.setTelphone(telphone);// Set 电话号码
		suggestion.setEmail(email);// Set 电子邮箱
		suggestion.setPublishUserType(publishUserType);// Set 反馈人类型[1-农户 | 2-专家 | 3-管理员]
		suggestion.setIsDeal(isDeal);// Set 是否解决[1-是 | 2-否 默认2]
		suggestion.setDealContent(dealContent);// Set 解决方案
		suggestion.setDealUserId(dealUserId);// Set 解决人标识
		suggestion.setDealUserType(dealUserType);// Set 解决人类型[1-农户 | 2-专家  | 3-管理员]
		suggestion.setCreateTime(createTime);// Set 反馈时间
		suggestion.setUpdateTime(updateTime);// Set 更新时间[初始化=创建时间]
		this.suggestionMapper.insert(suggestion);
		return suggestion.getSuggestionId();
	}

   /**
	* 删除问题反馈
	* @param suggestionId 主键值
	*/
	@Transactional
	public void delete(Long suggestionId) {
		this.suggestionMapper.delete(suggestionId);
	}

   /**
	* 更新问题反馈
	* @param suggestionId 反馈标识[主键值]
	* @param status 反馈状态[1-可用 | 2-不可用]
	* @param title 反馈标题
	* @param categoryId 问题类型
	* @param content 反馈内容
	* @param publishUserId 反馈人标识
	* @param publishUserType 反馈人类型[1-农户 | 2-专家 | 3-管理员]
	* @param isDeal 是否解决[1-是 | 2-否 默认2]
	* @param dealContent 解决方案
	* @param dealUserId 解决人标识
	* @param dealUserType 解决人类型[1-农户 | 2-专家  | 3-管理员]
	* @param createTime 反馈时间
	* @param updateTime 更新时间[初始化=创建时间]
	*/
    @Transactional
	public void edit(Long suggestionId, Integer status, String title, Long categoryId, String content, Long publishUserId, Integer publishUserType, Integer isDeal, String dealContent, Long dealUserId, Integer dealUserType, Long createTime, Long updateTime) {
	    // 构造问题反馈参数实体
		Suggestion suggestion = new Suggestion();
		suggestion.setSuggestionId(suggestionId);// Set 反馈标识[主键值]
		suggestion.setStatus(status);// Set 反馈状态[1-可用 | 2-不可用]
		suggestion.setTitle(title);// Set 反馈标题
		suggestion.setCategoryId(categoryId);// Set 问题类型
		suggestion.setContent(content);// Set 反馈内容
		suggestion.setPublishUserId(publishUserId);// Set 反馈人标识
		suggestion.setPublishUserType(publishUserType);// Set 反馈人类型[1-农户 | 2-专家 | 3-管理员]
		suggestion.setIsDeal(isDeal);// Set 是否解决[1-是 | 2-否 默认2]
		suggestion.setDealContent(dealContent);// Set 解决方案
		suggestion.setDealUserId(dealUserId);// Set 解决人标识
		suggestion.setDealUserType(dealUserType);// Set 解决人类型[1-农户 | 2-专家  | 3-管理员]
		suggestion.setCreateTime(createTime);// Set 反馈时间
		suggestion.setUpdateTime(updateTime);// Set 更新时间[初始化=创建时间]
		this.suggestionMapper.update(suggestion);
	}

   /**
	* 主键查询问题反馈
	* @param suggestionId 主键值
	* @return Suggestion 实体
	*/
	@Transactional(readOnly = true)
	public Suggestion queryById(Long suggestionId) {
		return this.suggestionMapper.selectById(suggestionId);
	}

   /**
	* 根据条件查询问题反馈列表
	* @param suggestionId 反馈标识[主键值]
	* @param status 反馈状态[1-可用 | 2-不可用]
	* @param title 反馈标题
	* @param categoryId 问题类型
	* @param content 反馈内容
	* @param publishUserId 反馈人标识
	* @param publishUserType 反馈人类型[1-农户 | 2-专家 | 3-管理员]
	* @param isDeal 是否解决[1-是 | 2-否 默认2]
	* @param dealContent 解决方案
	* @param dealUserId 解决人标识
	* @param dealUserType 解决人类型[1-农户 | 2-专家  | 3-管理员]
	* @param createTime 反馈时间
	* @param updateTime 更新时间[初始化=创建时间]
	* @return List<Suggestion> 实体List
	*/
    @Transactional(readOnly = true)
	public List<Suggestion> queryList(Long suggestionId, Integer status, String title, Long categoryId, String content, Long publishUserId, Integer publishUserType, Integer isDeal, String dealContent, Long dealUserId, Integer dealUserType, Long createTime, Long updateTime) {
		// 构造问题反馈参数实体
		Suggestion suggestion = new Suggestion();
		suggestion.setSuggestionId(suggestionId);// Set 反馈标识[主键值]
		suggestion.setStatus(status);// Set 反馈状态[1-可用 | 2-不可用]
		suggestion.setTitle(title);// Set 反馈标题
		suggestion.setCategoryId(categoryId);// Set 问题类型
		suggestion.setContent(content);// Set 反馈内容
		suggestion.setPublishUserId(publishUserId);// Set 反馈人标识
		suggestion.setPublishUserType(publishUserType);// Set 反馈人类型[1-农户 | 2-专家 | 3-管理员]
		suggestion.setIsDeal(isDeal);// Set 是否解决[1-是 | 2-否 默认2]
		suggestion.setDealContent(dealContent);// Set 解决方案
		suggestion.setDealUserId(dealUserId);// Set 解决人标识
		suggestion.setDealUserType(dealUserType);// Set 解决人类型[1-农户 | 2-专家  | 3-管理员]
		suggestion.setCreateTime(createTime);// Set 反馈时间
		suggestion.setUpdateTime(updateTime);// Set 更新时间[初始化=创建时间]
		return this.suggestionMapper.selectList(suggestion);
	}

}